package tech.xs.auth.domain.enums.result;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import tech.xs.common.framework.domain.enums.ApiResultEnum;

import java.util.HashMap;
import java.util.Map;

public enum LoginResultEnum implements ApiResultEnum {

    ACCOUNT_NOT_INIT(1000, "账户未初始化"),
    IMAGE_VERIFY_CODE_INVALID(1001, "验证码已过期"),
    IMAGE_VERIFY_CODE_ERROR(1002, "验证码错误");

    @EnumValue
    @JsonValue
    private final int value;
    private final String msg;

    private static final Map<Integer, LoginResultEnum> mappings = new HashMap<>(values().length);

    static {
        for (LoginResultEnum item : values()) {
            mappings.put(item.getValue(), item);
        }
    }

    LoginResultEnum(int value, String msg) {
        this.value = value;
        this.msg = msg;
    }

    @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
    public static LoginResultEnum create(int value) {
        return mappings.get(value);
    }

    @Override
    public Integer getValue() {
        return value;
    }

    @Override
    public String getMsg() {
        return msg;
    }
}
